package com.dst.service.impl;

import com.dst.dao.CategoryMapper;
import com.dst.eneity.Category;
import com.dst.service.CategoryService;
import com.dst.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class CategoryServiceImpl implements CategoryService {
    @Override
    public List<Category> selectAll() {
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        CategoryMapper mapper = sqlSession.getMapper(CategoryMapper.class);
        List<Category> categories = mapper.selectAll();
        return categories;
    }

    @Override
    public List<Category> selectCategory() {
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        CategoryMapper mapper = sqlSession.getMapper(CategoryMapper.class);
        List<Category> categories = mapper.selectCategory();
        return categories;
    }

    @Override
    public void delete(int id) {
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        CategoryMapper mapper = sqlSession.getMapper(CategoryMapper.class);
        mapper.delete(id);
        sqlSession.commit();
    }
}
